﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Document;

namespace Jbe.TestSuite.CodeEditor.Completion.Demain
{
    public class Utilities
    {
        public static string WordBeforeCaret(TextEditor textEditor)
        {
            int offset = textEditor.SelectionStart;
            int next_p = TextUtilities.GetNextCaretPosition(
                textEditor.Document,
                offset,
                System.Windows.Documents.LogicalDirection.Backward,
                CaretPositioningMode.WordStart
                );
            if (next_p < 0)
            {
                return "";
            }
            else
            {
                return textEditor.Document.GetText(next_p, offset - next_p);
            }
        }
    }
}
